﻿using Oracle.DataAccess.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using Helper;

namespace DataAccess.ProxyConnections
{
    class DatabaseProxy
    {
        private OracleConnection _connection;

        public OracleConnection getAUTHConnection()
        {
            //Todo read from web config or textfile
            try
            {
                _connection = new OracleConnection();
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("Data Source={0};user id={1};password={2};"
                    , (string)ConfigurationManager.AppSettings["ORACLE_AUTH_DB_URL"]
                    , (string)ConfigurationManager.AppSettings["ORACLE_AUTH_DB_USER"]
                    , (string)ConfigurationManager.AppSettings["ORACLE_AUTH_DB_PASS"]);
                _connection.ConnectionString = sb.ToString();
                //Auto_commit=false;
                return _connection;
            }
            catch (Exception e)
            {
                new FileHandle().insertErrorLogFile(e.ToString(), "getAUTHConnection");
                throw new Exception();
            }
        }

        public OracleConnection getBackoffcEjipConnection()
        {
            try
            {
                _connection = new OracleConnection();
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("Data Source={0};user id={1};password={2};"
                    , (string)ConfigurationManager.AppSettings["ORACLE_BACKOFFC_DB_URL"]
                    , (string)ConfigurationManager.AppSettings["ORACLE_BACKOFFC_DB_USER"]
                    , (string)ConfigurationManager.AppSettings["ORACLE_BACKOFFC_DB_PASS"]);
                _connection.ConnectionString = sb.ToString();
                //Auto_commit=false;
                return _connection;
            }
            catch (Exception e)
            {
                new FileHandle().insertErrorLogFile(e.ToString(), "getBackoffcEjipConnection");
                throw new Exception();
            }
        }
    }
}
